const merge = require("webpack-merge");
const common = require("./webpack.common");
const path = require("path");

module.exports = merge(common, {
    optimization: {
        runtimeChunk: "single",
        splitChunks: {
            cacheGroups: {
                vendor: {
                    test: /[\\/]node_modules[\\/]/,
                    name: "vendors",
                    chunks: "all"
                }
            }
        }
    },
    // devtool: "source-map",
    // optimization: {
    //     splitChunks: {
    //         cacheGroups: {
    //             commons: {
    //                 name: "commons",
    //                 chunks: "initial",
    //                 minChunks: 3
    //             }
    //         }
    //     }
    // },
    // devtool: "source-map",
    module: {
        rules: [
            {
                // 图片加载器，雷同file-loader，更适合图片，可以将较小的图片转成base64，减少http请求
                // 如下配置，将小于8192byte的图片转成base64码
                test: /\.(png|jpe?g|gif)$/,
                // exclude:[path.resolve(__dirname, "../src/css")],
                include: path.resolve(__dirname, "../src/images"),
                // loader: "url-loader?limit=8192&name=./static/images/[hash].[ext]",
                loader: "url-loader",
                options: {
                    limit: 8192,
                    name: "./images/[name].[ext]",
                    useRelativePath: false,
                    publicPath: "", // 图片的url前面追加'dist/images'
                    outputPath: ""
                },
            },
        ]
    },
    mode: "production"
    // mode: "development",
    // devtool: "source-map",
});
